package graph.impl;

import graph.design.Vertex;

import java.util.Iterator;
import java.util.LinkedList;

class VertexImpl<E extends Comparable<E>> implements Vertex<E>{
	
	private E v = null;
	
	private LinkedList<Vertex<E>> edgeList = null;

	VertexImpl(E v) {
		this.v = v;
		edgeList = new LinkedList<Vertex<E>>();
	}

	@Override
	public Iterator<Vertex<E>> getAdjacencyList() {
		return edgeList.iterator();
	}

	@Override
	public boolean addEdgeTo(Vertex<E> v) {
		boolean isAdded=false;
		if(!edgeList.contains(v)){
			isAdded=edgeList.add(v);
		}
		return isAdded;
	}

	@Override
	public boolean deleteEdgeTo(Vertex<E> v) {		
		return edgeList.remove(v);
		
	}	
	
	public E getVertex(){
		return v;
	}
	
	public String toString(){
		
		StringBuilder builder = new StringBuilder();		
		for(Vertex<E> v : edgeList){
			builder.append(v.getVertex().toString() + "," );
		}
		
		return builder.toString();
	}
	
	public static void main(String[] args) {
		
		VertexImpl<Integer> v1 = new VertexImpl<Integer>(1);
		VertexImpl<Integer> v2 = new VertexImpl<Integer>(2);
		VertexImpl<Integer> v3 = new VertexImpl<Integer>(3);
		
		v1.addEdgeTo(v2);
		v1.addEdgeTo(v3);
		
		v2.addEdgeTo(v1);
		v2.addEdgeTo(v3);
		
		v3.addEdgeTo(v1);
		v3.addEdgeTo(v2);
		
		System.out.println(v1.toString());
		System.out.println(v2.toString());
		System.out.println(v3.toString());
		
	}

}
